<template>
  <el-select
    v-model="selectId"
    clearable
    filterable
    :placeholder="$language.local('请选择')"
    @change="selectChange"
    class="el-select"
  >
    <el-option
      v-for="(item, index) in options"
      :key="index"
      :label="item[this.labeldto]"
      :value="item.Id || item.ID || item.id || item.BANKID"
    >
    </el-option>
  </el-select>
</template>

<script>
export default {
  props: {
    value: [String, Number],
    label: String,
    apiName: String,
  },
  data() {
    return {
      selectId: parseInt(this.value),
      options: [],
      labeldto: this.label,
    };
  },
  created() {
    this.getOptions();
  },
  watch: {
    value(newValue) {
      this.selectId = newValue;
    },
  },
  methods: {
    async getOptions() {
      let response = await this.$http.get(this.apiName);
      console.log(response);
      this.options = response.data.Data;
    },
    selectChange(e) {
      this.$emit("input", e);
    },
  },
};
</script>

<style lang="less" scoped>
.el-select {
  width: 100%;
}
</style>
